import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:syn_4s/core/extension/build_context_extension.dart';
import 'package:syn_4s/core/extension/int_extension.dart';
import 'package:syn_4s/ui/widgets/permit_to_work_item.dart';

import '../../core/model/permit_to_work_model.dart';
import '../../core/viewmodel/main_view_model.dart';
import 'main_fold.dart';

class MainPermitToWork extends StatelessWidget {
  final Key? scrollKey;
  final MainViewModel viewModel;
  final String? title;

  const MainPermitToWork(
      {super.key, this.scrollKey, required this.viewModel, this.title});

  @override
  Widget build(BuildContext context) {
    return MainFold(
      scrollKey: scrollKey,
      title: title ?? context.l10n.permit_to_work,
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 8.px),
        height: 200.px,
        child: Obx(() => ListView.separated(
            separatorBuilder: (ctx, index) {
              return VerticalDivider(
                thickness: 1.px,
                color: Colors.white,
                indent: 8.px,
                endIndent: 8.px,
              );
            },
            scrollDirection: Axis.horizontal,
            itemCount: viewModel.permitToWorks.length,
            itemBuilder: (ctx, index) {
              Dwss item = viewModel.permitToWorks[index];
              String iconSrc = "assets/images/risc.svg";
              if (item.code == "CleanCheck") {
                iconSrc = "assets/images/cleaning_inspection.svg";
              } else if (item.code == "SecurityCheck") {
                iconSrc = "assets/images/security_check.svg";
              }
              return PermitToWorkItem(
                iconSrc: iconSrc,
                title: item.name ?? "",
              );
            })),
      ),
    );
  }
}
